/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.dataaccess.hibernate;

import cassys.dataaccess.EvaluationDAO;
import cassys.datatransferobjects.EvaluationDTO;
import cassys.datatransferobjects.EvaluationItemDTO;
import cassys.exceptions.HibernateAccessLayerException;
import java.util.ArrayList;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Priyanka
 */
public class EvaluationDAOImpl extends AbstractDao implements EvaluationDAO {

    @Override
    public void insertEvaluation(EvaluationDTO dto) {
          Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting assessment " + dto.getEvaluationId() );
     try {
            super.saveOrUpdate(dto);
           List<EvaluationItemDTO> items = new ArrayList<EvaluationItemDTO>();
               items=   dto.getEvalutionItems();
            for (int i =0; i< items.size(); i++) {
                insertEvaluationItem(items.get(i));
            }
        
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());            
        }   
    }
    
    @Override
    public EvaluationDTO findEvaluationByAssess(String assessmentId) {
        EvaluationDTO p = null;
       try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding Evaluation" + assessmentId);
            p = (EvaluationDTO) super.findByParam(EvaluationDTO.class, "assessmentId", assessmentId);
            
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
       return p;
    }
    
    @Override
    public void insertEvaluationItem(EvaluationItemDTO dto) {
         try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting evaluation item" + dto.getEvalutionItemId() +" for evaluation "+ dto.getEvaluationId());
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void updateEvaluation(EvaluationDTO dto) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteEvaluation(String evaluationId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public EvaluationDTO findEvaluation(String evaluationId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<EvaluationDTO> findAllEvaluation() {
        try {
            return (ArrayList<EvaluationDTO>) super.findAll(EvaluationDTO.class);
            } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    

    @Override
    public void updateEvaluationItem(EvaluationItemDTO dto) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteEvaluationItem(String evalutionItemId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public EvaluationItemDTO findEvaluationItem(String evaluationItemId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<EvaluationItemDTO> findAllEvaluationItems() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
